<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<div class="button_area">
	<a class="button" onclick=GridOption.doDelete() id="delete">批量删除</a>
	<a href="task/task.add.action" class="button">发布新任务</a>
</div>
<div class="filter_area">
	<s:form>
		<tr>
			<td>
				<table>
					<s:textfield  name="filter.any" size="50"></s:textfield>
				</table>
			</td>
			<td style="padding-bottom: 6px" valign="bottom">
				<a href="javascript:void(0)" onclick="GridOption.doSearch()">搜索</a>
			</td>
		</tr>

	</s:form>
</div>
<script type="text/javascript">

var GridOption={            
			url:'task/taskList.action?'+$('form').serialize(),
     		datatype: 'json',  
     		jsonReader:{ root: "dataRows"},   
    		colModel:[       
       			{label:'任务Id',name:'taskId',hidden:true,index:'taskId',key:true,width:30,editable:false },     
       			{label:'任务名称',name:'taskName',index:'taskName',required:true, width:100,editable:false},     
        		{label:'任务开始时间',name:'startTime',index:'startTime', width:100,editable:false},       
        		{label:'任务结束时间',name:'endTime',index:'endTime', width:100,editable:false},
        		{label:'任务地点',name:'taskAddress',index:'taskAddress', width:100,editable:false},   
        		{label:'任务状态',name:'taskStatus.dictionaryName',index:'taskStatus.dictionaryName', width:100,editable:false},   
        		{label:'任务接收人',name:'user.userName',index:'user.userName', width:100,editable:false},   
        		{label:'接收人电话',name:'user.phoneNumber',index:'user.phoneNumber', width:100,editable:false},          
        		{label:'详情',name:'detail', width:100,align:'center',sortable:false}
     		],     
     		imgpath: '../theme/images/jqgrid/',      
    		pager: "#pjmap",   
      		multiselect: true,     
     		sortname: 'taskId',     
      		viewrecords: true,     
      		sortorder: "desc",     
      		jsonReader: {     
	      		root: "dataRows",
	      		repeatitems : false
     		},
     		gridComplete: function(){
				var ids = jQuery("#list").jqGrid('getDataIDs');
				for(var i=0;i < ids.length;i++){
					var cl = ids[i];
					var data=jQuery("#list").jqGrid('getRowData',cl);
						

					sc= "<a href='task/task.info.action?taskId="+ids[i]+"'>详情</a>";
					jQuery("#list").jqGrid('setRowData',ids[i],{detail:sc});
				}
			},
			doDelete:function(){
    			var ids = jQuery("#list").jqGrid('getDataIDs');
    			var values="";
    			var count = 0;
    			var deleteIds;
 				$('input[type=checkbox][name!=null]:checked').each(function(i,checkbox){
 					if(i==0){
 							values=ids[i];
 					}else{
 							values=values+","+ids[i];
 					}
 					count++;
 				});
 				if(count > 0){
    				$("#list").delGridRow(values,{url:'task/taskDelete.action?values='+values,caption:'请确认',msg:'确认删除所选'+count+'个任务吗?',bSubmit:'确认',bCancel:'取消',reloadAfterSubmit:true});
    			}
    		},
    		
    		doSearch:function(){
    			$("#list").setGridParam({url:"task/taskList.action?"+$('form').serialize()});
      			$("#list").trigger("reloadGrid");
    		},
    		width:$(document).width()-80,
    		height: $(document).height()-160
    		
    };
</script>
